package cn.com.pc.content.domain.risk;

import cn.com.pc.content.domain.content.Content;
import cn.com.pc.content.domain.content.ContentType;
import cn.com.pc.content.service.RiskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
 * 内容风险评估接口
 */
@Service
public class RiskEvaluator {

    @Autowired
    private RiskService riskService;

    /**
     * 根据内容类型, 分析出待评估的风险项
     * @param content
     */
    public Set<Risk> evaluate(Content content, ContentType contentType){
        Set<Risk> risks = new HashSet<Risk>();
        risks.add(censorPlatformRisk(content, contentType));
        risks.add(keywordRisk(content, contentType));
        if(hasVideo(content, contentType)){
            //TODO add video censorship
        }
        riskService.batchCreate(risks);
        return risks;
    }


    private Risk censorPlatformRisk(Content content, ContentType contentType){
        Risk risk = new Risk();
        risk.setScenes(RiskScenes.censorPlatform);
        risk.setContentId(content.getId());
        risk.setSite(content.getSite());
        risk.setContentType(contentType);
        risk.setAuthorId(content.getAuthor().getPassportId());
        return risk;
    }

    private Risk keywordRisk(Content content, ContentType contentType){
        Risk risk = new Risk();
        risk.setScenes(RiskScenes.keyword);
        risk.setContentId(content.getId());
        risk.setSite(content.getSite());
        risk.setContentType(contentType);
        risk.setAuthorId(content.getAuthor().getPassportId());
        return risk;
    }

    private boolean hasVideo(Content content, ContentType contentType){
        //TODO
        return false;
    }
}
